{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DeepResearchAgent\n",
    "\n",
    "`DeepResearchAgent` helps break down complex tasks into smaller steps, using web scraping and other techniques to find the information you need. Instead of handling everything at once, it tackles each part step by step, making research easier and more efficient. Whether you're looking for specific details, gathering data, or just trying to solve a tricky problem, this agent does the heavy lifting for you."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Installation\n",
    "\n",
    "**Note:** `DeepResearchAgent` is built on top of [`Browser Use`](https://github.com/browser-use/browser-use), which requires **Python 3.11 or higher**.\n",
    "\n",
    "\n",
    "To get started with the `DeepResearchAgent` agent, follow these steps:\n",
    "\n",
    "1. Install AG2 with the `browser-use` extra:\n",
    "   ```bash\n",
    "   pip install -U ag2[openai,browser-use]\n",
    "   ```\n",
    "   > **Note:** If you have been using `autogen` or `ag2`, all you need to do is upgrade it using:  \n",
    "   > ```bash\n",
    "   > pip install -U autogen[openai,browser-use]\n",
    "   > ```\n",
    "   > or  \n",
    "   > ```bash\n",
    "   > pip install -U ag2[openai,browser-use]\n",
    "   > ```\n",
    "   > as `autogen`, and `ag2` are aliases for the same PyPI package.  \n",
    "2. Set up Playwright:\n",
    "   \n",
    "   ```bash\n",
    "   # Installs Playwright and browsers for all OS\n",
    "   playwright install\n",
    "   # Additional command, mandatory for Linux only\n",
    "   playwright install-deps\n",
    "   ```\n",
    "\n",
    "3. For running the code in Jupyter, use `nest_asyncio` to allow nested event loops.\n",
    "    ```bash\n",
    "    pip install nest_asyncio\n",
    "    ```\n",
    "\n",
    "\n",
    "You're all set! Now you can start solving complex tasks.\n",
    "\n",
    "### Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "import nest_asyncio\n",
    "\n",
    "from autogen.agents.experimental import DeepResearchAgent\n",
    "\n",
    "nest_asyncio.apply()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Starting the Conversation\n",
    "\n",
    "This code initializes `DeepResearchAgent` and asks it to find out `What was the impact of DeepSeek on stock prices and why?` using `gpt-5`.\n",
    "\n",
    "> **Note:** Models like `gpt-5-nano` often don’t perform well enough for complex tasks."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "llm_config = {\n",
    "    \"config_list\": [{\"model\": \"gpt-5\", \"api_key\": os.environ[\"OPENAI_API_KEY\"]}],\n",
    "}\n",
    "\n",
    "agent = DeepResearchAgent(\n",
    "    name=\"DeepResearchAgent\",\n",
    "    llm_config=llm_config,\n",
    ")\n",
    "\n",
    "message = \"What was the impact of DeepSeek on stock prices and why?\"\n",
    "\n",
    "run_result = agent.run(\n",
    "    message=message,\n",
    "    tools=agent.tools,\n",
    "    max_turns=2,\n",
    "    user_input=False,\n",
    "    summary_method=\"reflection_with_llm\",\n",
    ")\n",
    "\n",
    "run_result.process()\n",
    "run_result.summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "front_matter": {
   "description": "DeepResearch Agent",
   "tags": [
    "agents",
    "browser-use",
    "DeepResearch",
    "webscraping",
    "function calling"
   ]
  },
  "kernelspec": {
   "display_name": ".venv-browser-use",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
